package com.imay.videorecord;


import com.imay.videorecord.camera.CameraEngine;
import com.imay.videorecord.filter.helper.MagicFilterType;
import com.imay.videorecord.utils.ImayParams;
import com.imay.videorecord.encoder.view.MagicCameraView;

/**
 * Created by ZhouZeChao on 2016/2/25.
 */
public class MagicEngine {
    private static MagicEngine magicEngine;

    public static MagicEngine getInstance(){
        if(magicEngine == null)
            magicEngine = new MagicEngine();

        return magicEngine;
    }

    private MagicCameraView mMagicCameraView;

    public void setmMagicCameraView(MagicCameraView mMagicCameraView) {
        this.mMagicCameraView = mMagicCameraView;
    }

    /**
     * 录像回调参数
     */
    public interface MagicEngineMovChangeListener{

    }

    private MagicEngineMovChangeListener changeListener;

    public MagicEngineMovChangeListener getChangeListener() {
        return changeListener;
    }

    public void setChangeListener(MagicEngineMovChangeListener changeListener) {
        this.changeListener = changeListener;
    }

    private MagicEngine(){

    }

    public void setFilter(MagicFilterType type){
        mMagicCameraView.setFilter(type);
    }

    // 开始录制
    public void startRecord(boolean isVolue) {
        if (mMagicCameraView instanceof MagicCameraView) {
            mMagicCameraView.setIsVolue(isVolue);
            mMagicCameraView.changeRecordingState(true);
        }
    }

    // 停止录制
    public void stopRecord(){
        if(mMagicCameraView instanceof MagicCameraView){
            mMagicCameraView.changeRecordingState(false);
        }
    }

    public void setFlashMode(int flashMode) {
        CameraEngine.setFlashMode(flashMode);
    }

    public static class Builder{

        public MagicEngine build(MagicCameraView magicBaseView) {
            if(magicEngine == null){
                magicEngine = MagicEngine.getInstance();
            }
            magicEngine.setmMagicCameraView(magicBaseView);
            return magicEngine;
        }

        public Builder setVideoPath(String path){
            ImayParams.videoPath = path;
            return this;
        }

        public Builder setVideoName(String name){
            ImayParams.videoName = name;
            return this;
        }

    }
}
